import { HintBtnBase } from "../HintBtnBase";
import { SDominionWillOpenNote } from "../../../../Message/Public/SDominionWillOpenNote";
import { Cache } from "../../cache/Cache";
import { ClockManager } from "../../manager/ClockManager";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { RemainTimeTool } from "../award/RemainTimeTool";
import { ObjCreate } from "../common/ObjCreate";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class DominionWarHintBtn
    
    export  class DominionWarHintBtn extends HintBtnBase
    {
        constructor(arg1: string, arg2: int=1)
        {
            super(arg1, arg2);
            return;
        }

        /* internal  */get openInfo(): SDominionWillOpenNote
        {
            return Cache.instance.dominion.willOpenNoteInfo;
        }

        /* internal  */get nowDate(): Date
        {
            return ClockManager.instance.nowDate;
        }

        /* internal  */startTimer(): void
        {
            if (Cache.instance.dominion.isBattleOpen) 
            {
                this._cdTxt.text = "";
            }
            else 
            {
                if (!this._secTimer) 
                {
                    this._secTimer = new SecTimer();
                    this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimerRun);
                }
                this._secTimer.reset();
                this._secTimer.start();
            }
            return;
        }

        /* internal  */stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        /* internal  */onTimerRun(arg1: SecTimer): void
        {
            var loc1=NaN;
            var loc2=null;
            if (this.openInfo) 
            {
                loc1 = this.openInfo.startDate.time - this.nowDate.time;
                loc1 = loc1 / 1000;
                if (loc1 >= 0) 
                {
                    loc2 = "#ffff00";
                    this._cdTxt.htmlText = RemainTimeTool.getRemainTimeByMillisecond(loc1, loc2, loc2, 12);
                }
                else 
                {
                    this._cdTxt.text = "";
                    this.stopTimer();
                }
            }
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            this._cdTxt = ObjCreate.createGTextField("", 0, 0, 50, 25, this);
            this._cdTxt.autoSize = "center";
            this._cdTxt.y = this._iconBtn.y + this._iconBtn.height;
            return;
        }

        protected /* override */ onIconBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.OnDominionUIOpen));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show();
            this.startTimer();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.stopTimer();
            return;
        }

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_cdTxt: GTextFiled;
    }
